package ${action.packageName};

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.water.smart.system.service.SysCodeService;
import ${context.bean.fullName};
import ${context.service.fullName};
import com.water.smart.web.WebResult;


/**
 * Generated by devtool.
 * 
 * @author ${author}
 *
 */
@Controller
@RequestMapping(value = "/${e.javaName?uncap_first}")
public class ${action.className} {
	private final static Logger log = LoggerFactory.getLogger(${action.className}.class);
	
	@Autowired
	protected SysCodeService sysCodeService;
	
    @Autowired
	private ${context.service.className} ${context.service.className?uncap_first};
	
	
	@RequestMapping(value = "${e.javaName?uncap_first}")
	public String ${e.javaName?uncap_first}() {
		log.debug("跳转到jsp页面:${e.javaName}");
		return "${context.modular}/${e.javaName}";
	}
	
@RequestMapping(value = "/search", produces = "application/json")
	@ResponseBody
	public WebResult search(Integer draw, Integer start, Integer length, Integer totalCount, ${e.javaName} ${e.javaName?uncap_first}) {
		log.debug("执行到了search方法");
		WebResult r = WebResult.success();
		if (start != null) {
			r.setRecordStart(start);
		}
		if (length != null) {
			r.setPageSize(length);
		}
		if (totalCount != null) {
			r.setRecordsTotal(totalCount);
		}

		List list = ${e.javaName?uncap_first}Service.search(r,${e.javaName?uncap_first});
		<#assign count=0 col='' dic=''>
		<#list listx as x>
		<#if x.codeType!=''>
		<#if count=0>
		<#assign col="\""+x.dbName?upper_case+"\"">
		<#assign dic="\""+x.codeType+"\"">
		<#else>
		<#assign col = col+","+"\""+x.dbName?upper_case+"\"">
		<#assign dic = dic+","+"\""+x.codeType+"\"">
		</#if>
		    <#assign count=1>
		</#if>
		</#list>
		<#if count=1>
		sysCodeService.addView(list, new String[] { ${col} }, new String[] {${dic}});
		</#if>
		r.setRecordsFiltered(r.getRecordsTotal());

		if (list == null) {
			list = new ArrayList();
		}
		log.debug("符合条件数量：{}", list.size());
		r.add("list", list);
		return r;
	}
	
	@RequestMapping(value = "save${e.javaName}", produces = "application/json")
	@ResponseBody
	public WebResult save${e.javaName}(${e.javaName} ${e.javaName?uncap_first}) {
		log.debug("执行到了的save${e.javaName} 方法");
		${e.javaName?uncap_first}Service.save(${e.javaName?uncap_first});
		WebResult r = WebResult.success("操作成功");
		return r;
	}

	@RequestMapping(value = "delete${e.javaName}", produces = "application/json")
	@ResponseBody
	public WebResult delete${e.javaName}(${e.primaryColumn.javaType} ${e.primaryColumn.name}) {
		log.debug("执行到了的delete${e.javaName} 方法：{}",${e.primaryColumn.name});
		<#if e.logicDelete>
		${e.javaName?uncap_first}Service.logicDelete(${e.primaryColumn.name});
		<#else>
		${e.javaName?uncap_first}Service.delete(${e.primaryColumn.name});
		</#if>
		WebResult r = WebResult.success("操作成功");
		return r;
	}
	
	@RequestMapping(value = "deleteMultiple", produces = "application/json")
	@ResponseBody
	public WebResult deleteMultiple(String ids) {
		log.debug("执行到了的deleteMultiple 方法：{}",ids);
		if(StringUtils.isBlank(ids)){
		  return WebResult.fail("请先选择一行数据");
		}
		<#if e.logicDelete>
		${e.javaName?uncap_first}Service.logicDeleteMultiple(ids);
		<#else>
		${e.javaName?uncap_first}Service.deleteMultiple(ids);
		</#if>
		WebResult r = WebResult.success("操作成功");
		return r;
	}

	@RequestMapping(value = "get${e.javaName}", produces = "application/json")
	@ResponseBody
	public WebResult get${e.javaName}(${e.primaryColumn.javaType} ${e.primaryColumn.name}) {
		log.debug("执行到了的get${e.javaName} 方法：{}",${e.primaryColumn.name});
		${e.javaName} ${e.javaName?uncap_first} = ${e.javaName?uncap_first}Service.get(${e.primaryColumn.name});
		WebResult r = WebResult.success();
		r.add("${e.javaName?uncap_first}", ${e.javaName?uncap_first});
		return r;
	}
	
	  
	


}
